row,col = map(int,input().split())
lines = []
for i in range(0,row):
    line = input()
    lines.append(line)

startX = -1
startY = -1
endX = -1
endY = -1

for i in range(0,row):
    for j in range(0,col):
        if lines[i][j] == 'S':
            startX = i
            startY = j
        elif lines[i][j] == 'T':
            endX = i
            endY = j


visit = [[]]
canto = [[]]
canfrom = [[]]
turn = [[1,0],[-1,0],[0,1],[0,-1]]

def init_array():
    array = []
    global row
    global col
    for i in range(0,row):
        array.append([False for j in range(0,col)])
    return array

def find_canto(i,j):
    global visit
    global canto
    global turn
    global row
    global col
    global lines
    visit[i][j] = True
    canto[i][j] = True
    for k in range(0,4):
        x = turn[k][0] + i
        y = turn[k][1] + j
        if x < 0 or y < 0 or x >= row or y >= col:
            continue
        if visit[x][y] or lines[x][y] == '#':
            continue
        if lines[i][j] == 'S' or lines[i][j] == 'T' or lines[i][j] == '+':
            find_canto(x,y)
        elif lines[i][j] == '.' and x == i + 1 and y == j:
            find_canto(x,y)
        elif lines[i][j] == '|' and y == j:
            find_canto(x,y)
        elif lines[i][j] == '-' and x == i:
            find_canto(x,y)

def find_canfrom(i,j):
    global visit
    global canto
    global turn
    global row
    global col
    global lines
    visit[i][j] = True
    canfrom[i][j] = True
    for k in range(0,4):
        x = turn[k][0] + i
        y = turn[k][1] + j
        if x < 0 or y < 0 or x >= row or y >= col:
            continue
        if visit[x][y] or lines[x][y] == '#':
            continue
        if lines[x][y] == 'S' or lines[x][y] == 'T' or lines[x][y] == '+':
            find_canfrom(x,y)
        elif lines[x][y] == '|' and y == j:
            find_canfrom(x,y)
        elif lines[x][y] == '-' and x == i:
            find_canfrom(x,y)
        elif lines[x][y] == '.' and x == i - 1 and y == j:
            find_canfrom(x,y)


visit = init_array()
canto = init_array()
find_canto(startX,startY)

if canto[endX][endY] is False:
    print("I'm stuck!")
    exit(0)

visit = init_array()
canfrom = init_array()
find_canfrom(endX,endY)

result=0
for i in range(0,row):
    for j in range(0,col):
        if canto[i][j]==True and canfrom[i][j]==False:
            result+=1

print(result)
